home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / attacvb4 / send32.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-07-30  |  6.6 KB  |  208 lines

  1. VERSION 4.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "Form1"
  4.    ClientHeight    =   2385
  5.    ClientLeft      =   3720
  6.    ClientTop       =   3150
  7.    ClientWidth     =   3825
  8.    Height          =   2790
  9.    Left            =   3660
  10.    LinkTopic       =   "Form1"
  11.    LockControls    =   -1  'True
  12.    MaxButton       =   0   'False
  13.    MinButton       =   0   'False
  14.    ScaleHeight     =   2385
  15.    ScaleWidth      =   3825
  16.    Top             =   2805
  17.    Width           =   3945
  18.    Begin VB.Frame Frame1 
  19.       Caption         =   "Send Attachment"
  20.       Height          =   2175
  21.       Left            =   120
  22.       TabIndex        =   0
  23.       Top             =   120
  24.       Width           =   3615
  25.       Begin VB.CommandButton Command1 
  26.          Caption         =   "Send Attachment"
  27.          Height          =   375
  28.          Left            =   1320
  29.          TabIndex        =   4
  30.          Top             =   1560
  31.          Width           =   2055
  32.       End
  33.       Begin VB.TextBox Text3 
  34.          Height          =   285
  35.          Left            =   1320
  36.          TabIndex        =   3
  37.          Top             =   1080
  38.          Width           =   2055
  39.       End
  40.       Begin VB.TextBox Text2 
  41.          Height          =   285
  42.          Left            =   1320
  43.          TabIndex        =   2
  44.          Top             =   720
  45.          Width           =   2055
  46.       End
  47.       Begin VB.TextBox Text1 
  48.          Height          =   285
  49.          Left            =   1320
  50.          TabIndex        =   1
  51.          Top             =   360
  52.          Width           =   2055
  53.       End
  54.       Begin MailLib.mMail Mail1 
  55.          Left            =   120
  56.          Top             =   1560
  57.          _Version        =   327680
  58.          _ExtentX        =   847
  59.          _ExtentY        =   847
  60.          _StockProps     =   0
  61.          Blocking        =   -1  'True
  62.          Debug           =   0
  63.          Host            =   ""
  64.          Timeout         =   0
  65.          ConnectType     =   0
  66.          PopPort         =   110
  67.          SmtpPort        =   25
  68.       End
  69.       Begin VB.Label Label3 
  70.          Alignment       =   1  'Right Justify
  71.          Caption         =   "File:"
  72.          Height          =   255
  73.          Left            =   360
  74.          TabIndex        =   7
  75.          Top             =   1080
  76.          Width           =   855
  77.       End
  78.       Begin VB.Label Label2 
  79.          Alignment       =   1  'Right Justify
  80.          Caption         =   "SMTP Server:"
  81.          Height          =   255
  82.          Left            =   120
  83.          TabIndex        =   6
  84.          Top             =   720
  85.          Width           =   1095
  86.       End
  87.       Begin VB.Label Label1 
  88.          Alignment       =   1  'Right Justify
  89.          Caption         =   "To:"
  90.          Height          =   255
  91.          Left            =   360
  92.          TabIndex        =   5
  93.          Top             =   360
  94.          Width           =   855
  95.       End
  96.    End
  97. Attribute VB_Name = "Form1"
  98. Attribute VB_Creatable = False
  99. Attribute VB_Exposed = False
  100. Private Sub Command1_Click()
  101.     Dim boundary As Double
  102.     Dim strFilename As String
  103.     On Error GoTo Some_Err
  104.     'validate entries
  105.     If Text1.Text = "" Or Text2.Text = "" Or Text3.Text = "" Then
  106.         MsgBox "Please fill in all values.", vbExclamation, "Missing Value"
  107.         Exit Sub
  108.     End If
  109.     strFilename = GetFileFromPath
  110.     Mail1.Debug = 1
  111.     'create a new message
  112.     Mail1.Action = MailActionNewMessage
  113.     Mail1.Date = Format$(Now(), "ddd, dd mmm yyyy hh:mm:ss")
  114.     '
  115.     'Your user friendly name
  116.     Mail1.From = "Your Name"
  117.     '
  118.     'The return e-mail address
  119.     Mail1.EMailAddress = "you@yourdomain.com"
  120.     '
  121.     'the lucky recipient
  122.     Mail1.To = Text1.Text
  123.     Mail1.Subject = "Example of attachments"
  124.     'create the headers for the message
  125.     '
  126.     'each multi-part message must have the 'parts'
  127.     'separated by a unique boundry.
  128.     boundary = Fix(Rnd * 100000000000#)
  129.     Mail1.ContentType = "multipart"
  130.     Mail1.ContentSubtype = "mixed"
  131.     Mail1.ContentSubtypeParameters = "boundary=" & CStr(boundary) & "_boundary"
  132.     Mail1.MultipartBoundary = CStr(boundary) & "_boundary"
  133.     'this is the attachment 'part'
  134.     Mail1.Action = MailActionCreatePart
  135.     Mail1.Action = MailActionDescend
  136.     Mail1.ContentType = "application"
  137.     Mail1.ContentSubtype = "x-uuencode"
  138.     Mail1.ContentSubtypeParameters = "name=" & Chr$(34) & _
  139.         strFilename & Chr$(34)
  140.     Mail1.ContentTransferEncoding = "x-uuencode"
  141.     Mail1.ContentDisposition = "attachment; filename=" & Chr$(34) & strFilename & Chr$(34)
  142.     Mail1.Flags = MailSrcIsFile Or MailDstIsBody
  143.     Mail1.SrcFilename = Text3.Text
  144.     Mail1.Action = MailActionEncode
  145.     Mail1.Action = MailActionAscend
  146.     'create the text 'part' of the message
  147.     Mail1.Action = MailActionCreatePart
  148.     Mail1.Action = MailActionDescend
  149.     Mail1.ContentType = "text"
  150.     Mail1.ContentSubtype = "plain"
  151.     Mail1.ContentSubtypeParameters = "charset=us-ascii"
  152.     Mail1.ContentTransferEncoding = "7bit"
  153.     Mail1.Body(0) = "This is the text 'part'"
  154.     Mail1.Action = MailActionAscend
  155.     'basic host configuration
  156.     Mail1.Blocking = True
  157.     Mail1.Host = Text2.Text
  158.     Mail1.ConnectType = MailConnectTypeSMTP
  159.     'send the message
  160.     Command1.Enabled = False
  161.     MousePointer = 11
  162.     Mail1.Action = MailActionConnect
  163.     Mail1.Flags = MailDstIsHost
  164.     Mail1.Action = MailActionWriteMessage
  165.     Mail1.Action = MailActionDisconnect
  166.     MousePointer = 0
  167.     Command1.Enabled = True
  168.     Exit Sub
  169. Some_Err:
  170.     MsgBox CStr(Err.Number) & " " & Err.Description
  171.     On Error Resume Next
  172.     Mail1.Action = MailActionDisconnect
  173.     MousePointer = 0
  174.     Command1.Enabled = True
  175. End Sub
  176. Private Sub Form_Load()
  177. End Sub
  178. Private Sub Frame1_DragDrop(Source As Control, X As Single, Y As Single)
  179. End Sub
  180. Private Sub Label1_Click()
  181. End Sub
  182. Private Sub Mail1_Debug(ByVal Message As String)
  183.     Debug.Print Message
  184. End Sub
  185. Private Function GetFileFromPath() As String
  186.     '
  187.     'this is a crude hack used to determine
  188.     'a filename from a complete path/file
  189.     '
  190.     'loop through the complete path/file
  191.     'backwards, looking for the first
  192.     '"\" char.
  193.     Dim i As Integer
  194.     i = Len(Text3.Text)
  195.     For i = Len(Text3.Text) To 1 Step -1
  196.         If Mid$(Text3.Text, i, 1) = "\" Then
  197.             Exit For
  198.         End If
  199.     Next i
  200.     If i > 1 Then
  201.         GetFileFromPath = Right$(Text3.Text, Len(Text3.Text) - i)
  202.     Else
  203.         GetFileFromPath = Text3.Text
  204.     End If
  205. End Function
  206. Private Sub Text1_Change()
  207. End Sub
  208.